namespace C1.Util
{
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;

    internal class CFGraphics
    {
        internal static ImageAttributes _attEmpty = new ImageAttributes();

        internal static void DrawImage(Graphics g, Image img, Rectangle rc)
        {
            DrawImage(g, img, rc, _attEmpty);
        }

        internal static void DrawImage(Graphics g, Image img, Rectangle rc, Color transparent)
        {
            ImageAttributes att = new ImageAttributes();
            if (transparent != Color.Transparent)
            {
                att.SetColorKey(transparent, transparent);
            }
            DrawImage(g, img, rc, att);
        }

        internal static void DrawImage(Graphics g, Image img, Rectangle rc, ImageAttributes att)
        {
            int num = (rc.Width - img.Width) / 2;
            if (num > 0)
            {
                rc.X += num;
            }
            num = (rc.Height - img.Height) / 2;
            if (num > 0)
            {
                rc.Y += num;
            }
            g.DrawImage(img, rc, 0, 0, rc.Width, rc.Height, GraphicsUnit.Pixel, att);
        }

        internal static void DrawImage(Graphics g, Image img, Rectangle rimg, Rectangle rsrc, Color transparent)
        {
            ImageAttributes imageAttr = new ImageAttributes();
            if (transparent != Color.Transparent)
            {
                imageAttr.SetColorKey(transparent, transparent);
            }
            g.DrawImage(img, rimg, rsrc.X, rsrc.Y, rsrc.Width, rsrc.Height, GraphicsUnit.Pixel, imageAttr);
        }

        internal static void DrawString(Graphics g, string s, Font f, Brush b, Rectangle r, StringFormat fmt)
        {
            g.DrawString(s, f, b, r, fmt);
        }

        internal static SizeF MeasureString(Graphics g, string s, Font f, int wid, StringFormat sf)
        {
            return g.MeasureString(s, f);
        }
    }
}

